@extends('layout.index')
@section('content')
    <style>
        body {
            background-color: $ffffff;
        }
    </style>  
<body>
<div class="layui-form layuimini-form">
    <div class="layui-form-item">
        <label class="layui-form-label required">分类名称</label>
        <div class="layui-input-block">
            <input type="text" name="cat_name" lay-verify="required" lay-reqtext="标题不能为空" placeholder="请输入标题" value="" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label required">分类排序</label>
        <div class="layui-input-block">
            <input type="text" name="cat_sort" lay-verify="required" lay-reqtext="分类排序不能为空" placeholder="1-100越小越靠前" value="" class="layui-input">
        </div>
    </div>
 
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认保存</button>
        </div>
    </div>
</div>


<script>
    layui.use(['form'], function () {
        var form = layui.form,
            layer = layui.layer,
            $ = layui.$;

        //监听提交
        form.on('submit(saveBtn)', function (data) {
            // var index = layer.alert(JSON.stringify(data.field), {
            //     title: '最终的提交信息'
            // }, function () {

            //     // 关闭弹出层
            //     layer.close(index);

            //     var iframeIndex = parent.layer.getFrameIndex(window.name);
            //     parent.layer.close(iframeIndex);

            // });
            $.ajaxSetup({
                headers:{'X-CSRF-TOKEN': '{{csrf_token()}}'}
            });
            $.post('/admin/category', data.field, function(res){
                if (res.status=='success') {
                    location.href='/admin/category'
                }
            });
            // 关闭弹出层
            layer.close(index);
            return false;
        });

    });
</script>
</body>
@endsection